package com.xuecheng.auth.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

/**
 * @author: Hes
 * @description aoAuthenticationProvider效验了密码，重写DaoAuthenticationProviderCustom，
 * 自己实现密码效验
 * @date: 2023/6/26 10:55
 */
@Component
@Slf4j
public class DaoAuthenticationProviderCustom extends DaoAuthenticationProvider {
    /**
     * 注入自定义的userDetailsService，到DaoAuthenticationProvider
     *
     * @param userDetailsService
     * @Autowired作用在普通方法上，会在注入的时候调用一次该方法，如果方法中有实体参数，
     * 会对方法里面的参数进行装配，并调用一次该方法。这个可以用来在自动注入的时候做一些初始化操作
     */
    @Autowired
    public void setUserDetailsService(UserDetailsService userDetailsService) {
        super.setUserDetailsService(userDetailsService);
    }

    /**
     * 重写效验密码的方法，自己实现，这里空着即可
     *
     * @param userDetails
     * @param authentication
     * @throws AuthenticationException
     */
    @Override
    protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {

    }
}
